<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const {
          WebChat: { renderWebChat }
        } = window; // Imports in UMD fashion.

        const clock = lolex.createClock();
        const { directLine, store } = testHelpers.createDirectLineEmulator({ ponyfill: clock });

        renderWebChat(
          {
            directLine,
            ponyfill: clock,
            store,
            styleOptions: {
              typingAnimationBackgroundImage: `url('')`
            }
          },
          document.getElementById('webchat')
        );

        // WHEN: Web Chat has been rendered for 600 ms.
        await pageConditions.webChatRendered();
        clock.tick(600);

        // THEN: Connection status should be gone.
        await pageConditions.uiConnected();

        // WHEN: Bot send a typing indicator.
        await directLine.emulateIncomingActivity({
          from: { id: 'u-00001', name: 'Bot', role: 'bot' },
          timestamp: 2,
          type: 'typing'
        });

        // THEN: Should display typing indicator.
        await pageConditions.typingIndicatorShown();

        // WHEN: t = 5s
        clock.tick(5000);

        // THEN: Should not display typing indicator.
        await pageConditions.typingIndicatorHidden();

        // WHEN: An OOO message arrive.
        await directLine.emulateIncomingActivity({
          from: { id: 'u-00001', name: 'Bot', role: 'bot' },
          text: 'Non minim nulla ex consectetur cupidatat id quis.',
          timestamp: 1,
          type: 'message'
        });

        // THEN: Should display the message.
        await pageConditions.numActivitiesShown(1);

        // THEN: Should not display typing indicator because typing started at t=2 ms but now is t = 5002 ms.
        await pageConditions.typingIndicatorHidden();
      });
    </script>
  </body>
</html>
